<?php echo $this->render('header.phtml'); ?>
<?php echo $this->render('menu.phtml'); ?>
<div id="content">
    <div id="icon" class="icon32"><br/></div><h2>编辑日志</h2>
    <div id="tabs">
        <ul>
            <li><a href="#tabs-1">内容</a></li>
            <li><a href="#tabs-2">分类</a></li>
            <li><a href="#tabs-3">标签</a></li>
        </ul>
        <form action="/backend/<?php if($this->do == 'edit'): ?>edit/<?php else: ?>add/<?php endif; ?>article/" method="post" onsubmit="return submitForm();">
            <div id="tabs-1" class="editor-area">
                <div class="titlebox">
                    <h3><span>标题</span></h3>
                    <input type="text" class="title" id="article_title" name="article_title" autocomplete="off" value="<?php if($this->do == 'edit') echo $this->articleInfo->info->articleTitle ?>" tabindex="1" size="80" />
                </div>
                <div>
                    <h3><span>日志</span></h3>
                    <textarea cols="100" id="article_content" name="article_content" rows="10">
                        <?php if($this->do == 'edit') echo $this->articleInfo->info->articleContent; ?>
                    </textarea>
                </div>
                <div>
                    <h3><span>摘要</span></h3>
                    <textarea cols="100" id="article_summary" name="article_summary" rows="2">
                        <?php if($this->do == 'edit') echo $this->articleInfo->info->articleSummary; ?>
                    </textarea>
                </div>
                <div id="message-box" class="ui-state-error ui-corner-all" style="display: none;padding: 12px;">
                    <p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: 12px;"></span>
                        <strong>警告:</strong> <span id="error-message"></span>
                    </p>
                </div>
                <div>
                    <input id="publish" type="submit" value="发布" name="publish"/>
                    <input id="articleId" type="hidden" value="<?php if($this->do) echo $this->articleInfo->info->articleId ?>" name="articleId" />
                </div>
            </div>
            <div id="tabs-2" class="editor-area">
                <div id="other">
                    <h3><span>分类</span></h3>
                    <?php if(null !== $this->categoryTree): ?>
                    <ul>
                            <?php foreach ($this->categoryTree as $category) : ?>
                        <li><input type="radio" name="category_id" value="<?php echo $this->escape($category->parent->categoryId) ?>" <?php if($this->do == 'edit') : if($category->parent->categoryId == $this->articleInfo->category->categoryId): ?>checked="true"<?php endif; endif;?> ><?php echo $this->escape($category->parent->categoryName) ?>
                                    <?php if(property_exists($category, 'childs')) : ?>
                            <ul>
                                            <?php foreach ($category->childs as $child) : ?>
                                <li><input type="radio" name="category_id" value="<?php echo $this->escape($child->categoryId) ?>" <?php if($this->do == 'edit') : if($child->categoryId == $this->articleInfo->category->categoryId && $this->do == 'edit'): ?>checked="true"<?php endif; endif;?>><?php echo $this->escape($child->categoryName) ?></li>
                                            <?php endforeach; ?>
                            </ul>
                                    <?php endif; ?>
                        </li>
                            <?php endforeach; ?>
                    </ul>
                    <?php else: ?>
                    暂无分类，请先添加分类再添加日志!
                    <?php endif; ?>

                </div>
            </div>
            <div id="tabs-3" class="editor-area">
                <div id="other">
                    <h3><span>Tag标签</span></h3>
                    <input type="text" class="title" id="article_tags" name="article_tags" autocomplete="off" tabindex="1" size="80" value="<?php if($this->do == 'edit') echo $this->escape($this->tags) ?>" />
                </div>
            </div>
        </form>
    </div>
</div>
<script type="text/javascript" src="/public/editor/ckeditor/ckeditor.js"></script>
<script type="text/javascript">
    $(function() {
        $("#tabs").tabs({
            collapsible: true
        });
    });

    function submitForm(){
        var category_id = 0;
        $("input[type=radio][name=category_id]").each(function(){
            if(this.checked) {
                category_id = this.value;
            }
        });

        if ($("#article_tags").val() == '') {
            $("#message-box").show();
            $("#error-message").empty();
            $("#error-message").append("请输入日志标签!");
            return false;
        } else if (category_id == 0) {
            $("#message-box").show();
            $("#error-message").empty();
            $("#error-message").append("请选择日志分类!");
            return false;
        } else if($("#article_title").val() == ''){
            $("#message-box").show();
            $("#error-message").empty();
            $("#error-message").append("请输入日志标题!");
            return false;
        } else if ($("#article_content").val() == '') {
            $("#message-box").show();
            $("#error-message").empty();
            $("#error-message").append("请输入日志内容!");
            return false;
        } else if ($("#article_summary").val() == '') {
            $("#message-box").show();
            $("#error-message").empty();
            $("#error-message").append("请输入日志摘要!");
            return false;
        } else{
            return true;
        }
    }

    CKEDITOR.replace('article_content',
    {
        toolbar :
            [
            ['Cut','Copy','Paste','PasteText','PasteFromWord'],
            ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
            ['Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField'],
            '/',
            ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
            ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
            ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
            ['Link','Unlink','Anchor'],
            ['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak'],
            '/',
            ['Styles','Format','Font','FontSize'],
            ['TextColor','BGColor'],
            ['Maximize', 'ShowBlocks','Source']
        ],
        filebrowserBrowseUrl : '/public/editor/ckfinder/ckfinder.html',
        filebrowserImageBrowseUrl : '/public/editor/ckfinder/ckfinder.html?Type=Images',
        filebrowserFlashBrowseUrl : '/public/editor/ckfinder/ckfinder.html?Type=Flash',
        filebrowserUploadUrl : '/public/editor/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files',
        filebrowserImageUploadUrl : '/public/editor/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
        filebrowserFlashUploadUrl : '/public/editor/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash'
    });

    CKEDITOR.replace('article_summary',
    {
        height: 120,
        toolbar :
            [
            ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
            ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
            ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
            ['Link','Unlink','Anchor'],
            ['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak'],
            '/',
            ['Styles','Format','Font','FontSize'],
            ['TextColor','BGColor'],
            ['Maximize', 'ShowBlocks','Source']
        ]
    });
</script>
<?php echo $this->render('footer.phtml'); ?>